/*
* Model.hpp
* Defines the SparseMatrix class for use by Lsqr
*
*/

#ifndef SPARSEMATRIX_H
#define SPARSEMATRIX_H

#include "LsqrTypes.h"
//#include "test_lsqr.hpp"

#include <stdio.h>
#include <stdlib.h> 
#include <map>
#include <vector>
#include <string>
#include <fstream>
#include <QTextStream>
#include <QTime>
class SparseMatrix {

public:
private:
  bool CRS_CCS;
  float* pDataRow;
  int* row_ind;
  int* col_ptr;

  float* pDataCol;
  int* col_ind;
  int* row_ptr;

  uint32 nrow;
  uint32 ncol;
  uint32 numElts;
//  int32 *rowIndex;
//  uint32 *colStarts;
//  double  *values;
//  double  *rowUpper;
//  double  *rowLower;
//  double  *colUpper;
//  double  *colLower;
//  double  *rhs;
  std::map<int, float> data;
  std::map<int, std::vector<int>> row_col_index;
  std::map<int, std::vector<int>> col_row_index;
  QTextStream* logTextStream;

public:
  SparseMatrix(uint32 rowSiz, uint32 colSiz){
    nrow = rowSiz;
    ncol = colSiz;
    logTextStream = NULL;
    CRS_CCS = false;

    pDataRow = NULL;
    row_ind = NULL;
    col_ptr = NULL;

    pDataCol = NULL;
    col_ind = NULL;
    row_ptr = NULL;

 //   prod = new PROD_DATA;
  } 

  ~SparseMatrix(){
      data.clear();
      delete[] pDataRow;
      delete[] row_ind;
      delete[] col_ptr;

      delete[] pDataCol;
      delete[] col_ind;
      delete[] row_ptr;
  }

  void TransferToCRS_CCSStroage();

uint32 rowSize(){
    return nrow;
  }  
  
uint32 colSize(){
    return ncol;
  }  
int elementSize()
{
    numElts = data.size();
    return numElts;
}

void SetLogTextStream(QTextStream* p);

void matVecMult( long, dvec *, dvec *);

void RowCopy(int rowCpyFrom, int rowCpyTo);
void ColCopy(int colCpyFrom, int ColCpyTo);

float GetElement(int row, int col);

void SetElement(int row, int col, float value);

void OutputMatrix(std::string fileName);
  
};
#endif
